package org.dg.dgimg.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.dg.dgimg.entity.User;
import org.dg.dgimg.mapper.UserMapper;
import org.dg.dgimg.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author DG
 * @since 2024-06-25
 */
@Slf4j
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public User selectUserByMailAndPassword(String mail, String password) {
        try {
            return userMapper.selectUserByMailAndPassword(mail, password);
        } catch (Exception e) {
            log.error("UserServiceImpl selectUserByMailAndPassword error", e.getMessage());
            return null;
        }

    }

    @Override
    public int insertUser(User user) {
        try {
            userMapper.insertUser(user);
            return 1;
        } catch (Exception e) {
            log.error("UserServiceImpl insertUser error", e.getMessage());
            return 0;
        }
    }

    @Override
    public int selectUserCountByMail(String mail) {
        try {
            return userMapper.selectUserCountByMail(mail);
        } catch (Exception e) {
            log.error("UserServiceImpl selectUserCountByMail error", e.getMessage());
            return -1;
        }

    }
}
